<%@ page language="java" pageEncoding="UTF-8"%>
<!-- 明细与列表在同一个页面 -->
 <div id="detail" style="display:none;">
 	<form id="formdetail" name="formdetail" method="post"></form>
 </div>
 
<style>
	.l-form ul {
		padding:5px;
	}
</style>

  <script type="text/javascript">
      //编辑，新增弹出框
      var detailWin = null, curentData = null, currentIsAddNew;
	  var formdetail = $("#formdetail");
	  var form = null;
      function FF_ShowDialog(data, isAddNew)
      {
    	  var datas = parent.genResults();
          curentData = data;
          currentIsAddNew = isAddNew;
          if (detailWin){
              detailWin.show(); 
          }else{
              //创建表单结构, 这里的字段命名为了与同其它地方区分，加了SDdetail_前缀，后台获取数据时也得去掉前缀(若明细与列表不在同一页面时，可不用)
              form = formdetail.ligerForm({ 
                  fields: [
					{ name: "SDdetail_id", type: "hidden" },
					{ name: "csId", type: "hidden" },
 					{ display: "钻取字段", name: "SDdetail_fieldName", newline: true, labelWidth: 60, width: 350, space: 30, type: "select",
							comboboxName: "SDdetail_linkName", options:{data:datas,valueFieldID:"SDdetail_fieldName"}},
					{ display: "窗口名称", name: "SDdetail_name", newline: true, labelWidth: 60, width: 350, space: 30, type: "text"}, 
					{ display: "标题", name: "SDdetail_title", newline: true, labelWidth: 60, width: 350, space: 30, type: "text"},
					{ display: "打开类型", name: "SDdetail_openTypeDesc", newline: true, labelWidth: 60, width: 350, space: 30, type: "select",
						options:{data:${openType},valueFieldID:"SDdetail_openType"}},
					{ display: "关联参数", name: "SDdetail_params", newline: true, labelWidth: 60, width: 350, space: 30, type: "text"},
					{ display: "CSS", name: "SDdetail_css", newline: true, labelWidth: 60, width: 350, space: 30, type: "text"},
					{ display: "关联报表", name: "linkReport", newline: true, labelWidth: 60, width: 350, space: 30, type: "select",
						options:{data:${otherReport},valueFieldID:"linkReportId"}
					},
					{display:  "关联URL", name: "SDdetail_linkURL", newline: true, labelWidth: 60, width: 350, space: 30, type: "text"},
					{ display: "关联编码", name: "SDdetail_linkCode", newline: true, labelWidth: 60, width: 350, space: 30, type: "text"}
         		],
                toJSON: JSON2.stringify
              });
              
			  $("[ligeruiid=linkReport]").change(function(){ 
				   var baseRedirect = "/report/view/report/report.do?reportTemplateCode=";
				   $("[ligeruiid=SDdetail_linkURL]").val(baseRedirect+$("[ligeruiid=linkReport]").val().split("/")[0].replace(/\s\S/,""));
				   $("[ligeruiid=SDdetail_linkCode]").val($("#linkReportId").val().replace(/\s\S/,""));
			  });
			  $("[ligeruiid=SDdetail_params]").attr("placeholder","field1:常量;field2:$\{fieldName\};");
			  $("[ligeruiid=SDdetail_linkCode]").attr("placeholder","编码唯一,如果为另外一张报表则为报表ID,支持自定义");
			  
              detailWin = $.ligerDialog.open({
            	  title: '编辑钻取字段',
                  target: $("#detail"),
                  width: 600, height: 400,top:10,
                  buttons: [
					  { text: '取消', onclick: function () { detailWin.hide(); }, className: 'fa fa-close' },
	                  { text: '保存', onclick: function () { FF_Save(); }, className: 'fa fa-check' }
                  ]
              });
          }
         
          if (curentData)
          {
        	  form._setData({'SDdetail_id':curentData.pkId,'SDdetail_linkName':curentData.linkName,'SDdetail_fieldName':curentData.fieldName,'SDdetail_name':curentData.name,
        		  'SDdetail_title':curentData.title,'SDdetail_openTypeDesc':curentData.openType,'SDdetail_params':curentData.params,
        		  'SDdetail_css':curentData.css,'linkReport':curentData.linkCode,'SDdetail_linkURL':curentData.linkURL,'SDdetail_linkCode':curentData.linkCode});
           }else{
        	   formdetail[0].reset();
          }
          $("#csId").val("${csId}");
          
      }
     jQuery.metadata.setType("attr", "validate"); 
     LG.validate(formdetail);
     function FF_Save(){
        	  formdetail.attr("action","${baseURL}/report/link/linksave/save.do");
        	  LG.submitForm(formdetail, function (data) {
                if (data && data.hasOk) {  
                     grid.loadData();
                     detailWin.hide();
                     alert('操作成功!');
                } else { 
                	 alert("操作失败!失败信息如下:\n"+data.message+"\n如您对以上信息有疑问，请联系管理人员!");
                }
              });
    }
  </script>
